// pages/yonghu/index.js

const db = wx.cloud.database()

Page({

    /**
     * 页面的初始数据
     */
    data: {

    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面显示
     */

    onShow: function () {
        db.collection('users').where({
            xinwentype: '普通用户'
        }).get().then(res => {
            console.log(res);
            this.setData({
                list: res.data
            })
        })
    },

    shanchu(e) {

        let that = this;
        wx.showModal({
            title: '温馨提示',
            content: '是否删除？',
            confirmText: "是",
            cancelText: "否",
            success(res) {
                if (res.confirm) {
                    wx.showLoading({
                        title: '删除中',
                    })

                    wx.cloud.callFunction({
                        name: "update",
                        data: {
                            action: "shanchuyonghu",
                            id: e.currentTarget.dataset.id,
                        }
                    }).then(res => {
                        wx.hideLoading({
                            success: (res) => {},
                        })
                        console.log(res);
                        db.collection('users').where({
                            xinwentype: '普通用户'
                        }).get().then(res => {
                            console.log(res);
                            that.setData({
                                list: res.data
                            })
                        })

                    })


                } else if (res.cancel) {


                }
            }
        })
    }

})